package sdk8.io.beanSaveLocal;

import java.io.*;

/**
 * 将一个java对象 保存到磁盘
 */
public class demo1 {
    public static void main(String[] args) throws IOException {
        //save();
        read ();
    }

    public static void save() throws IOException {
        TestBean testBean = new TestBean();
        testBean.setId(1);
        testBean.setPass("123");

        File file = new File("D://a.txt");
        FileOutputStream ou = new FileOutputStream(file);
        ObjectOutputStream oout = new ObjectOutputStream(ou);
        oout.writeObject(testBean);
    }

    public static void  read () throws IOException {
        FileInputStream fin = new FileInputStream("D://a.txt");
        ObjectInputStream in = new ObjectInputStream(fin);
        try {
            TestBean o = (TestBean) in.readObject();
            System.out.println(o);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
